package com.hockeo.client.ui.base;

import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.google.gwt.user.client.ui.Widget;

/**
 * Base class for all panels used within the VH application.
 *
 * @version $Id$
 * @author jjanke
 */
public abstract class VHPanel extends LayoutContainer
{
  private BorderLayoutData d_layoutDataNorth;
  private BorderLayoutData d_layoutDataSouth;
  private BorderLayoutData d_layoutDataCenter;
  private Widget           d_widgetCenter;

  public VHPanel()
  {
    setLayout( new BorderLayout() );
    setBorders( false );
    setAutoWidth( true );
    setLayoutOnChange( true );
  }

  protected BorderLayoutData getNorthLayoutData()
  {
    if ( d_layoutDataNorth == null )
    {
      d_layoutDataNorth = new BorderLayoutData( LayoutRegion.NORTH );
      d_layoutDataNorth.setMargins( new Margins( 4, 4, 4, 4 ) );
    }

    return d_layoutDataNorth;
  }

  protected BorderLayoutData getCenterLayoutData()
  {
    if ( d_layoutDataCenter == null )
    {
      d_layoutDataCenter = new BorderLayoutData( LayoutRegion.CENTER );
      d_layoutDataCenter.setMargins( new Margins( 0, 4, 4, 4 ) );
    }

    return d_layoutDataCenter;
  }

  protected BorderLayoutData getSouthLayoutData()
  {
    if ( d_layoutDataSouth == null )
    {
      d_layoutDataSouth = new BorderLayoutData( LayoutRegion.SOUTH );
      d_layoutDataSouth.setMargins( new Margins( 0, 4, 4, 4 ) );
    }

    return d_layoutDataSouth;
  }

  protected Widget getCenterWidget()
  {
    return d_widgetCenter;
  }

  protected void setCenterWidget( Widget widget )
  {
    // Remove current center widget (if there is one)
    //
    if ( d_widgetCenter != null )
      d_widgetCenter.removeFromParent();

    d_widgetCenter = widget;
    add( d_widgetCenter, getCenterLayoutData() );
  }
}
